home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8743 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  44 lines

  1. Path: news.eunet.fi!newsmaster
  2. From: mtg@neste.com (Michael Glasgow)
  3. Newsgroups: comp.lang.c
  4. Subject: How to make this get_time function work ?
  5. Date: 5 Mar 1996 14:34:05 GMT
  6. Organization: Neste Network Services, Finland
  7. Distribution: world
  8. Message-ID: <4hhjct$3og@idefix.eunet.fi>
  9. Reply-To: mtg@neste.com
  10. NNTP-Posting-Host: manager.kni.neste.com
  11.  
  12. #include <stdio.h>
  13. #include <ctype.h>
  14. #include <time.h>
  15. #include <math.h>
  16. #include <string.h>
  17. #define STRING_LENGTH 256
  18.  
  19. int get_time() {
  20.         time_t t=time(NULL);
  21.         struct tm *tp=localtime(&t);
  22.         char time_str[STRING_LENGTH]={0}, str[STRING_LENGTH]={0};
  23.         strftime(time_str, STRING_LENGTH, "%Y%m%d%H%M%S", tp);
  24.         sprintf(str,"%s",time_str);
  25. /*        printf("%s",str); */
  26.     return str;
  27. }
  28. main() {
  29.     int tim;
  30.     tim = get_time();
  31.     printf("%s\n", tim);
  32. }
  33.  
  34.  
  35. With gcc I get the following error messages:
  36. ../test.c: In function `get_time':
  37. ../test.c:15: warning: return makes integer from pointer without a cast
  38. ../test.c:15: warning: function returns address of local variable
  39.  
  40. and when I try to return str with atoi conversion --> return atoi(str);
  41. I can't get anything readable out, any ideas, thanks !
  42.  
  43. --
  44.